/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.scs.model.tableModel;

import com.wisnu.scs.entity.DbBarang;
import com.wisnu.scs.entity.DbBarangRekap;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Wisnu Wardoyo
 */
public class DbBarangTableModel extends AbstractTableModel {

    private List<DbBarang> listDbBarang = new ArrayList<>();
    private List<DbBarangRekap> listDbBarangRekap = new ArrayList<>();

    public void setListDbBarang(List<DbBarang> list) {
        this.listDbBarang = list;
    }

    public void setListDbBarangRekap(List<DbBarangRekap> listDbBarangRekap) {
        this.listDbBarangRekap = listDbBarangRekap;
    }

    public boolean add(DbBarang element) {
        try {
            return listDbBarang.add(element);
        } finally {
            fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
        }
    }

    public DbBarang get(int i) {
        return listDbBarang.get(i);
    }

    public DbBarang set(int index, DbBarang element) {
        try {
            return listDbBarang.set(index, element);
        } finally {
            fireTableRowsUpdated(index, index);
        }
    }

    public DbBarang remove(int index) {
        try {
            return listDbBarang.remove(index);
        } finally {
            fireTableRowsDeleted(index, index);
        }
    }

    @Override
    public int getRowCount() {
        return listDbBarang.size();
    }

    @Override
    public int getColumnCount() {
        return 5;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return listDbBarang.get(rowIndex).getIdBarang();
            case 1:
                return listDbBarang.get(rowIndex).getNamaBarang();
            case 2:
                return listDbBarangRekap.get(rowIndex).getJumlahMasuk();
            case 3:
                return listDbBarangRekap.get(rowIndex).getJumlahKeluar();
            case 4:
                return listDbBarang.get(rowIndex).getStock();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int index) {
        switch (index) {
            case 0:
                return "ID";
            case 1:
                return "Nama Barang";
            case 2:
                return "Jumlah Masuk";
            case 3:
                return "Jumlah Keluar";
            case 4:
                return "Stock";
            default:
                return null;
        }
    }

}
